﻿@using SH = EMoney.IStock.Client.Framework.StringHelper;

<div class="ind_l">
    <div class="renwu_menu"><a href="javascript:;" class="on" hidefocus="true">未完成任务</a><a href="javascript:;" hidefocus="true">已完成任务</a></div>
    <div class="renwu_k">
        <div id="scrollBox1" class="scrollBox" scrollflag style="height:235px;">
            <div id="divTaskList"></div>  
        </div>
    </div>
</div>
<div class="ind_r"> 
    @{Html.RenderAction("tasktips", "mc");}
</div>
<script type="text/javascript">
    $("#scrollBox1").height(235);
    $(".scrollBox").jscroll({ W: "8px", IW: "8px", CurrT: 0, Bar: { Pos: "up" }, Btn: { btn: false }, Fn: function () { } }).hover(function (e) {
        var thisbx = $(this), scrlbr = $(this).find(".jscroll-e");
        if (!scrlbr.hasClass("non")) {
            scrlbr.addClass("mon").stop(true, true, false).show();
        }
    }, function (e) {
        var thisbx = $(this), scrlbr = $(this).find(".jscroll-e");
        if (!scrlbr.hasClass("non")) {
            scrlbr.removeClass("mon");
            if (scrlbr.hasClass("vxdrag")) { } else {
                //scrlbr.fadeOut("slow");
            }
        }
    });

    //ReSetScroll();

    $("#divTaskList").delegate('.rw_part', 'click', '', function () {
        if ($(this).hasClass("ison")) {
            $(this).toggleClass("on").hasClass("on");

            ReSetScroll();
        }
    });

    $("#divTaskList").delegate('.go', 'click', '',function(e) {
        var tid = $(this).attr("tid");

        if (tid != undefined && tid != "") {
            if (tid == "1") {
                $(".bind")[0].click();
            }
            else {
                ISTOCK_FUNC_GOTASK(tid);
            }
            e.stopPropagation();
        }
    });

    $(".renwu_menu a").click(function () {
        $(".renwu_menu a").removeClass("on");
        $(this).addClass("on");

        var clknum = $(".renwu_menu a").index(this);

        var flag = "";
        if (clknum == 0) {
            flag = "0";
        }
        else if (clknum == 1) { //已完成任务
            flag = "1";
        }

        $.ajax({
            type: "post",
            url: www + "mc/tasklist",
            data: { flag: flag },
            datatype: "text",
            success: function (data) {
                if (data != "") {
                    var obj = eval('(' + data + ')');

                    if (obj != null && obj.length > 0) {
                        var taskList = "",taskType = "";

                        $.each(obj, function (i) {
                            switch (obj[i].Type) {
                                case 1:
                                    taskType = "一次性任务";
                                    break;
                                case 2:
                                    taskType = "日常任务";
                                    break;
                                default:
                                    taskType = "";
                                    break;
                            }
                            
                            if (obj[i].Description != undefined && obj[i].Description != "") {
                                taskList += "<div class=\"rw_part ison\" tid=\"" + obj[i].TaskID + "\">";
                            }
                            else {
                                taskList += "<div class=\"rw_part\" tid=\"" + obj[i].TaskID + "\" style='background:none;cursor:default;'>";
                            }

                            taskList += "<ul>";

                            switch (flag) {
                                case "1":
                                    if (obj[i].TaskID == 18) {  //连登任务
                                        var continueLoginDays = $("#hidContinueLoginDays").val();

                                        obj[i].iNum = getContinueLoginINum(continueLoginDays);
                                        taskList += "<li style=\"width:210px;\"><span>连续登录<span style='color:red';>" + continueLoginDays + "</span>天奖励</span></li>";
                                    }
                                    else {
                                        taskList += "<li style=\"width:210px;\"><span>" + obj[i].Name + "</span></li>";
                                    }

                                    taskList += "<li style=\"width:160px;\">" + taskType + "</li>";
                                    taskList += "<li style=\"width:60px;\">+ " + obj[i].iNum + "i豆</li>";
                                    taskList += "<div class=\"clear\"></div>";                                    
                                    break;
                                case "0":
                                    taskList += "<li style=\"width:190px;\">" + obj[i].Name + "</li>";
                                    taskList += "<li style=\"width:90px;\">+ " + obj[i].iNum + "i豆</li>";
                                    taskList += "<li style=\"width:90px;\">" + taskType + "</li>";
                                    taskList += "<li style=\"width:60px;\">";
                                    if (obj[i].IsGo == true) {
                                        taskList += "<a href=\"javascript:;\" class=\"go\" tid=\"" + obj[i].TaskID + "\" hidefocus='true'>去完成</a>";
                                    }
                                    taskList += "</li>";
                                    taskList += "<div class=\"clear\"></div>";
                                    break;
                                default:
                                    break;
                            }

                            if (obj[i].Description != undefined && obj[i].Description != "") {
                                taskList += "<div class=\"rwxq\"><span class=\"blue\">任务详情：</span><span style='color:#666;'>" + formatDescription(obj[i].Description) + "</span></div>";
                            }
                            
                            taskList += "</ul>";
                            taskList += "</div>";
                        });

                        $("#divTaskList").removeClass("task_loading");
                        $("#divTaskList").html(taskList);
                    }
                }
                else {
                    flag = "0";
                    switch (flag) {
                        case "0":
                            $("#divTaskList").html("当前无未完成任务");
                            break;
                        default:
                            $("#divTaskList").html("当前无已完成任务");
                            break;
                    }                    
                }

                ReSetScroll();
            },
            beforeSend: function () {
                $("#divTaskList").addClass("task_loading");                
                $("#divTaskList").html("数据加载中...");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //alert(XMLHttpRequest.status);
            }
        });
    });

    function formatDescription(description)
    {
        if (description == undefined || description == "") {
            return "";
        }
        else {
            if (description.indexOf("[school]") > -1) {
                description = description.replace("[school]", "<span class='schoolicon'></span>");
            }
            else if (description.indexOf("[shop]") > -1) {
                description = description.replace("[shop]", "<span class='shopicon'></span>");
            }
            else if (description.indexOf("[qq]") > -1) {
                description = description.replace("[qq]", "<span class='qqicon'></span>");
            }

            return description;
        }
    }

    function getContinueLoginINum(days)
    {
        var retINum = 5;
        switch (days) {
            case "1":
                retINum = 5;
                break;
            case "2":
                retINum = 10;
                break;
            case "3":
                retINum = 15;
                break;
            case "4":
                retINum = 20;
                break;
            case "5":
                retINum = 25;
                break;
            default:
                break;
        }

        return retINum;
    }

    $(".renwu_menu a")[0].click();
</script>